package cn.tedu.charging.common.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtil {

    private static ObjectMapper objectMapper=new ObjectMapper();

    public  static String toJson(Object o){
        String s="";
        try {
            s = objectMapper.writeValueAsString(o);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return s;
    }

    public static <T>T fromJson(String s,Class<T> tclass){
        try {
            return objectMapper.readValue(s, tclass);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }


}
